package com.axt.manager.bean;

import com.axt.soa.bean.*;
import com.axt.soa.msg.types.MsgParam;
import com.axt.manager.base.*;

public class LoginBean extends BaseFuncBean {
	private int userId;
	private String sesKey;
	private int roleId;

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public String getSesKey() {
		return sesKey;
	}

	public void setSesKey(String sesKey) {
		this.sesKey = sesKey;
	}

	public int getRoleId() {
		return roleId;
	}

	public void setRoleId(int roleId) {
		this.roleId = roleId;
	}

	public long queryTimestamp() {
		if (-1 == execute(MsgFuncExt.FUNC_GET_TIMESTAP, CONN_T_TCP)) {
			return -1;
		}

		return reply.getParam(MsgParam.PARA_TIMESTAP).toLong();
	}

	public int login(String userName, String passwd, long timestamp) {
		request.addParam(MsgParam.PARA_SVR_ID, "-10");
		request.addParam(MsgParam.PARA_USER_NAME, userName);
		request.addParam(MsgParam.PARA_PASSWD, passwd);
		request.addParam(MsgParam.PARA_TIMESTAP, timestamp);

		if (-1 == execute(MsgFuncExt.FUNC_LOGIN, CONN_T_TCP)) {
			return -1;
		}

		userId = reply.getParam(MsgParam.PARA_USER_ID).toInteger();
		sesKey = reply.getParam(MsgParam.PARA_SES_KEY).toString();
		roleId = reply.getParam(MsgParam.PARA_ROLE_ID).toInteger();

		return 0;
	}
	
	public void logout() {
		prepare();
		execute(MsgFuncExt.FUNC_LOGOUT, CONN_T_TCP);
	}
}
